<template>
<div class="col-md-12">
  <rd-widget>
    <rd-widget-header :header="header">
      <p class="text-danger" v-show="licenseError">{{licenseErrorStr}}</p>
    </rd-widget-header>
    <rd-widget-body>
      <my-list2 :list="list" :cfg="cfg"></my-list2>
    </rd-widget-body>
  <rd-widget>  
</div>
</template>

<script>
import _ from 'lodash'
import {codeStr} from 'libs/api.js'
import {systemApi} from 'share/server/api.js'
import locales from '../locales/licenseInfo.js'
import {List} from '../configs/licenseInfo.js'

export default {
  locales,
  data () {
    return {
      header: {
        icon: 'fa fa-list',
        title: this.$t("title")
      },
      cfg: {
        showHead: true,
        columns: [{
          width: '30%',
          name: this.$t("head.item")
        }, {
          width: '35%',
          name: this.$t("head.curr")
        }, {
          width: '35%',
          name: this.$t("head.limit")
        }]
      },
      list: new List(this)
    }
  },
  vuex: {
    getters: {
      licenseInfo: (state) => state.system.state.licenseInfo,
      platform: (state) => state.system.platform,
    }
  },
  computed: {
    licenseError () {
      return this.licenseInfo.stateCode != 0
    },
    licenseErrorStr () {
      return codeStr(this, this.licenseInfo.stateCode)
    }
  },
  methods: {
    init () {
      let licenseInfo = this.licenseInfo
      let limit = this.platform.limit

      _.forEach(this.list, (item) => {
        if (licenseInfo.license && licenseInfo.license.data) {
          if (typeof licenseInfo.license.data[item.field] != 'undefined') {
            item.columns[1].value = licenseInfo.license.data[item.field]
          }          
        }
        if (limit) {
          if (typeof limit[item.field] != 'undefined') {
            item.columns[2].value = limit[item.field]
          }
        }
      })
    }
  },
  ready () {
    this.init()
  }
}
</script>

<style>
</style>